namespace OneWorks.Utils.FluentData
{
    using System;
    using System.Linq.Expressions;

    internal class StoredProcedureBuilder<T> : BaseStoredProcedureBuilder, IStoredProcedureBuilder<T>
    {
        internal StoredProcedureBuilder(IDbCommand command, string name, T item)
            : base(command, name)
        {
            this.Data.Item = item;
        }

        public IStoredProcedureBuilder<T> Parameter(string name, object value, DataTypes parameterType, int size)
        {
            this.Actions.ColumnValueAction(name, value, parameterType, size);
            return this;
        }

        public IStoredProcedureBuilder<T> AutoMap(params Expression<Func<T, object>>[] ignoreProperties)
        {
            this.Actions.AutoMapColumnsAction(ignoreProperties);
            return this;
        }

        public IStoredProcedureBuilder<T> Parameter(Expression<Func<T, object>> expression, DataTypes parameterType, int size)
        {
            this.Actions.ColumnValueAction(expression, parameterType, size);

            return this;
        }

        public IStoredProcedureBuilder<T> ParameterOut(string name, DataTypes parameterType, int size = 0)
        {
            this.Actions.ParameterOutputAction(name, parameterType, size);
            return this;
        }

        public IStoredProcedureBuilder<T> UseMultiResult(bool useMultipleResultsets)
        {
            this.Data.Command.UseMultiResult(useMultipleResultsets);
            return this;
        }
    }

    internal class StoredProcedureBuilder : BaseStoredProcedureBuilder, IStoredProcedureBuilder
    {
        internal StoredProcedureBuilder(IDbCommand command, string name)
            : base(command, name)
        {
        }

        public IStoredProcedureBuilder Parameter(string name, object value, DataTypes parameterType, int size)
        {
            this.Actions.ColumnValueAction(name, value, parameterType, size);
            return this;
        }

        public IStoredProcedureBuilder ParameterOut(string name, DataTypes parameterType, int size = 0)
        {
            this.Actions.ParameterOutputAction(name, parameterType, size);
            return this;
        }

        public IStoredProcedureBuilder UseMultiResult(bool useMultipleResultsets)
        {
            this.Data.Command.UseMultiResult(useMultipleResultsets);
            return this;
        }
    }
}